﻿using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Description;
using System.Web.UI;

namespace Learun.Application.Web.AppApi
{
    /// <summary>
    /// 
    /// </summary>
    [RoutePrefix("api/CaseApi")]
    [HandlerApiLogin(FilterMode.Ignore)]
    [TokenAuthorize]
    public class CaseApiController : WebApiControllerBase
    {
        private ec_CaseBLL ec_CaseBLL;
        /// <summary>
        /// 
        /// </summary>
        public CaseApiController()
        {
            ec_CaseBLL = new ec_CaseBLL();
        }

        /// <summary>
        /// 获取所有的属性，和对象类型无关。
        /// </summary>
        /// <param name="ProjectId">空，或者0，则查询公司级</param>
        /// <returns></returns>
        [HttpGet]
        public IHttpActionResult GetCases(string ProjectId)
        {
            try
            {
                var res = ec_CaseBLL.GetList("{\"ProjectId\":\"" + ProjectId + "\"}");
                return Success(res);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 切换位号的当前case
        /// </summary>
        /// <param name="ProjectId"></param>
        /// <returns></returns>
        [HttpPost]
        public IHttpActionResult SwitchCase(string ProjectId, string NewCaseId, [FromBody] List<string> EngineDatas)
        {
            try
            {
                var res = ec_CaseBLL.SwitchCase(ProjectId, EngineDatas, NewCaseId);
                return Success(res);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
    }
}
